#include"ChessBoardImp.h"
#include <iostream>
#include <QFile>
#include <QtXml/qdom.h>
#include <QtXml/QDomElement>
#include <QtXml/QDomDocument>
#include <QtXml/QDomNode>

void ChessBoardImp::loadFile(const char* filename){

    QString pathname(":/layout/");
    pathname.append(filename);
    std::cout<<pathname.toStdString()<<std::endl;
    QFile file(pathname);
    QDomDocument doc;
    doc.setContent( &file );
    file.close();
    QDomElement docElem = doc.documentElement();
    QDomNodeList nodeList = docElem.elementsByTagName("ChessBoard");
    if (!nodeList.isEmpty())
    {
        for(int i = 0;i < nodeList.count(); i++)
        {
            for(int j=0;j<nodeList.at(i).attributes().count();j++){
                QString key(nodeList.at(i).attributes().item(j).nodeName());
                int value = nodeList.at(i).attributes().item(j).nodeValue().toInt();
                std::cout<<key.toStdString()<<" "<<value<<std::endl;
                _attributes[key.toStdString()] = value;
            }

        }
    }

}
void ChessBoardImp::setAttribute(std::string key,int value){
    _attributes[key] = value;
}
int ChessBoardImp::getAttribute(std::string key){
    return _attributes[key];
}
